package com.yuexun.dhdoctor.module.survey.adapter;

import android.view.View;
import android.widget.AbsListView;
import android.widget.TextView;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.baselistener.OnItemPartClickListener;
import com.yuexun.dhdoctor.module.survey.bean.SurveyDateBean;

import org.kymjs.kjframe.widget.AdapterHolder;
import org.kymjs.kjframe.widget.KJAdapter;

import java.util.Collection;

/**
 * Created by wangt on 2017/8/2.
 */

public class SurveyListAdapter extends KJAdapter<SurveyDateBean> {

    private OnItemPartClickListener listener;

    public void setOnItemPartClickListener(OnItemPartClickListener listener) {
        this.listener = listener;
    }

    public SurveyListAdapter(AbsListView view, Collection<SurveyDateBean> mDatas, int itemLayoutId) {
        super(view, mDatas, itemLayoutId);
    }

    @Override
    public void convert(AdapterHolder helper, SurveyDateBean item, boolean isScrolling, final int position) {
        super.convert(helper, item, isScrolling, position);
        helper.setText(R.id.tv_survey_title, item.getSurveyName());
        helper.setText(R.id.tv_survey_name, item.getTypeName());
        helper.setText(R.id.tv_survey_create, item.getCreateName());
        TextView status = helper.getView(R.id.tv_survey_status);
        TextView start = helper.getView(R.id.tv_survey_start);

        if (item.getExamStatus() == 1) {
            status.setText("未开始");
        } else if (item.getExamStatus() == 2) {
            status.setText("进行中");
        } else if (item.getExamStatus() == 3) {
            status.setText("已结束");
        }

        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.OnClick(0, position);
            }
        });
    }
}
